
layui.config({
    base: 'js/StatisticalReport/',
}).extend({
    excel: 'excel',
});

layui.use(['jquery', 'excel','form','layer','laydate'], function(){
    var form = layui.form,
        $ = layui.jquery,
        laydate = layui.laydate;
    var excel = parent.layui.excel;

    //执行一个laydate实例
    laydate.render({
        elem: '#start' //指定元素
    });

    form.on('submit(toolbarDemo)', function(){

        $.ajax({
            url: '/exportJJYLFYList',
            type: 'post',
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                console.log(data);

                // 1. 如果需要调整顺序，请执行梳理函数
                var dt = excel.filterExportData(data, [
                    'jgmc'
                    ,'jan'
                    ,'feb'
                    ,'mar'
                    ,'apr'
                    ,'may'
                    ,'jun'
                    ,'july'
                    ,'aug'
                    ,'sep'
                    ,'oct'
                    ,'nov'
                    ,'december'
                ]);

                // 2. 数组头部新增表头
                dt.unshift({jgmc: '机构名称', jan: '一月', feb: '二月', mar: '三月', apr: '四月', may: '五月', jun: '六月',
                    july: '七月', aug: '八月', sep: '九月', oct: '十月', nov: '十一月',december: '十二月'});

                // 意思是：A列40px，B列60px(默认)，C列120px，D、E、F等均未定义
                var colConf = excel.makeColConfig({
                    'C': 90,
                    'F': 80
                }, 60);

                var timestart = Date.now();
                // 3. 执行导出函数，系统会弹出弹框
                excel.exportExcel({
                    sheet1: dt
                }, '居家一类费用表.xlsx', 'xlsx', {
                    extend: {
                        '!cols': colConf
                    }
                });
                var timeend = Date.now();

                var spent = (timeend - timestart) / 1000;
                layer.alert('导出耗时 '+spent+' s');
                //setTimeout(function () {window.location.href='/findAdmin';},2000);
            },

            error: function () {
                //console.log(data);
                setTimeout(function () {window.location.href='/getJJYLFYList';},2000);
            }
        });
    });

    /*添加弹出框*/
    $("#addStudnetBtn").click(function () {
        layer.open({
            type:1,
            title:"添加宿舍",
            skin:"myclass",
            area:["50%"],
            anim:2,
            content:$("#test").html()
        });
        $("#addEmployeeForm")[0].reset();
        form.on('submit(formDemo)', function(data) {
            // layer.msg('aaa',{icon:1,time:3000});
            var param=data.field;
            // console.log(JSON.stringify(param));
            $.ajax({
                url: '/addDormitory',
                type: "post",
                data:JSON.stringify(param),
                contentType: "application/json; charset=utf-8",
                success:function(){
                    layer.msg('添加成功', {icon: 1, time: 3000});
                    setTimeout(function () {window.location.href='/findDormitory';},2000);

                },
                error:function(){
                    layer.msg('添加失败',{icon:0,time:3000});
                    setTimeout(function () {window.location.href='/findDormitory';},2000);
                }
            });
            // return false;
        });
    });

});


/*删除*/
function member_del(obj,d_id){
    layer.confirm('确认要删除吗？',function(index){
        //发异步删除数据
        $.get("/deleteDormitory",{"d_id":d_id},function (data) {
            if(data =true){
                layer.msg('删除成功!',{icon:1,time:2000});
                setTimeout(function () {window.location.href='/findDormitory';},2000);

            }else {
                layer.msg('删除失败!',{icon:1,time:2000});
                setTimeout(function () {window.location.href='/findDormitory';},2000);
            }
        });
    });
}